﻿Imports Global_Visas_Business_Layer
Imports System.ComponentModel
Imports System.Windows.Interop
Partial Public Class frmPaymentPlan

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSave.Click
        Dim tsk As New TasksEvents
        Dim frm As New frmCRMMainDisplay
        Try

            frm.blnCancelPaymentPlan = False
            If GlobalCRM.CurrentCaseID > 0 Then
                If cboPayment.SelectedValue = 0 Then
                    CommonFuncs.DisplayMessage("Please choose an option to save.", CommonDialog.CustomDialogIcons.Information, "Choose")
                Else
                    If CommonDataFunctions.UpdatePaymentPlan(GlobalCRM.CurrentCaseID, cboPayment.SelectedValue) = True Then
                        tsk.GblFunc_Add_Event("Payment Plan", "The payment plan :" & cboPayment.Text & " has been updated for the case.", TasksEvents.EventStatus.SingleEvent, GlobalCRM.CurrentCaseID, TasksEvents.EventTypes.EventCase)
                        CommonFuncs.DisplayMessage("The payment plan has been updated for the case", CommonDialog.CustomDialogIcons.Information, "Success")
                        Me.Close()
                    Else
                        CommonFuncs.DisplayMessage("There was an error updating the payment plan.Please try again.", CommonDialog.CustomDialogIcons.Information, "Error")

                    End If
                End If
            Else
                CommonFuncs.DisplayMessage("Please select the case to update the payment plan", CommonDialog.CustomDialogIcons.Information, "Select Case")
            End If
        Catch ex As Exception
        Finally
            tsk = Nothing
            frm = Nothing
        End Try
    End Sub

    Private Sub frmPaymentPlan_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles Me.KeyUp
        If e.Key = Key.Escape Then
            btnCancel_Click(sender, e)
        End If
    End Sub


    Private Sub frmPaymentPlan_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        GeneralTasks.ChangeTheme(Me)
        GeneralTasks.EnumerateandFill(Me.LogicalChildren)
        '        Me.Content = "Payment Plan for case : " & GlobalCRM.CurrentCaseID
        Me.Title = "Payment Plan for case : " & GlobalCRM.CurrentCaseID
        If GlobalCRM.CurrentCaseID > 0 Then
            With Me.cboPayment
                .SelectedValuePath = "id"
                .DisplayMemberPath = "descr"
                .ItemsSource = CType(CommonDataFunctions.LoadPaymentMode(), IListSource).GetList
                .SelectedValue = CommonDataFunctions.GetCasePaymentPlan(GlobalCRM.CurrentCaseID)
            End With

        Else
            btnSave.IsEnabled = False
            cboPayment.IsEnabled = False
            CommonFuncs.DisplayMessage("Please select a case number to set the payment plan.", CommonDialog.CustomDialogIcons.Information, "Select Case")
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnCancel.Click
        Dim frmCRMMaindisplay As New frmCRMMainDisplay
        Try
            frmCRMMaindisplay.blnCancelPaymentPlan = True
            Me.Close()
        Catch ex As Exception
        Finally
            frmCRMMaindisplay = Nothing
        End Try
    End Sub
End Class
